package cn.cyh.queue_service.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * WebSocket API 文档控制器
 * 用于在Swagger中显示WebSocket接口说明
 */
@Tag(name = "WebSocket", description = "WebSocket接口相关的API和文档")
@RestController
@RequestMapping("/api/websocket")
public class WebSocketDocController {
    
    /**
     * 队列状态WebSocket文档
     * 仅用于Swagger文档展示，不提供实际功能
     */
    @Operation(
        summary = "队列状态WebSocket接口", 
        description = "连接端点: ws://[服务器地址]/ws/queue-status\n\n" +
               "**URL参数:**\n" +
               "- businessTypeId (可选): 业务类型ID，指定接收特定业务类型的队列状态\n" +
               "- queueNumber (可选): 队列号码，指定接收特定号码的状态更新\n\n" +
               "**接收消息格式:**\n" +
               "```json\n" +
               "{\n" +
               "  \"messageType\": \"QUEUE_STATUS_UPDATE\",\n" +
               "  \"data\": {\n" +
               "    \"businessTypeId\": 1,\n" +
               "    \"businessTypeName\": \"普通业务\",\n" +
               "    \"waitingCount\": 10,\n" +
               "    \"currentNumber\": \"A001\",\n" +
               "    \"estimatedWaitTime\": 15\n" +
               "  },\n" +
               "  \"timestamp\": 1621234567890\n" +
               "}\n" +
               "```"
    )
    @ApiResponse(responseCode = "200", description = "请使用WebSocket客户端连接，此接口仅用于文档")
    @GetMapping("/queue-status")
    public ResponseEntity<String> queueStatusWebSocketDoc() {
        return ResponseEntity.ok("这是队列状态WebSocket接口的文档说明，请使用WebSocket客户端连接");
    }
    
    /**
     * 叫号大屏WebSocket文档
     * 仅用于Swagger文档展示，不提供实际功能
     */
    @Operation(
        summary = "叫号大屏WebSocket接口", 
        description = "连接端点: ws://[服务器地址]/ws/call-screen\n\n" +
               "**URL参数:**\n" +
               "- areaId (可选): 区域ID，指定接收特定区域的叫号信息\n\n" +
               "**接收消息格式:**\n" +
               "```json\n" +
               "{\n" +
               "  \"messageType\": \"CALL_NOTIFICATION\",\n" +
               "  \"data\": {\n" +
               "    \"queueNumber\": \"A005\",\n" +
               "    \"windowNumber\": \"3号窗口\",\n" +
               "    \"businessTypeName\": \"普通业务\",\n" +
               "    \"areaId\": 1,\n" +
               "    \"areaName\": \"一楼大厅\"\n" +
               "  },\n" +
               "  \"timestamp\": 1621234567890\n" +
               "}\n" +
               "```"
    )
    @ApiResponse(responseCode = "200", description = "请使用WebSocket客户端连接，此接口仅用于文档")
    @GetMapping("/call-screen")
    public ResponseEntity<String> callScreenWebSocketDoc() {
        return ResponseEntity.ok("这是叫号大屏WebSocket接口的文档说明，请使用WebSocket客户端连接");
    }
    
    /**
     * WebSocket客户端示例
     */
    @Operation(
        summary = "WebSocket客户端示例", 
        description = "JavaScript客户端连接示例:\n\n" +
               "```javascript\n" +
               "// 连接队列状态WebSocket\n" +
               "const socket = new WebSocket('ws://[服务器地址]/ws/queue-status?businessTypeId=1');\n\n" +
               "socket.onopen = function(event) {\n" +
               "  console.log('WebSocket连接已建立');\n" +
               "};\n\n" +
               "socket.onmessage = function(event) {\n" +
               "  const message = JSON.parse(event.data);\n" +
               "  console.log('收到消息:', message);\n" +
               "  // 处理消息...\n" +
               "};\n\n" +
               "socket.onclose = function(event) {\n" +
               "  console.log('WebSocket连接已关闭');\n" +
               "};\n\n" +
               "socket.onerror = function(error) {\n" +
               "  console.error('WebSocket错误:', error);\n" +
               "};\n" +
               "```"
    )
    @GetMapping("/client-example")
    public ResponseEntity<String> webSocketClientExample() {
        return ResponseEntity.ok("请参考API文档中的客户端示例代码");
    }
} 